package com.platform.comm.common.batch.listener.exportor;

import com.platform.vo.BatchResult;
import com.platform.comm.common.batch.ComBatchExportContext;
import lombok.extern.log4j.Log4j2;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;

/**
 * 步骤执行监听器
 * 用来在每个步骤完成的时候统计忽略和异常跳过的记录总数
 * @author Tommy
 */
@Log4j2
public class ComExportStepExecutionListener extends StepExecutionListenerSupport {
    private BatchResult batchResult;

    public ComExportStepExecutionListener(ComBatchExportContext comBatchExportContext) {
        this.batchResult = comBatchExportContext.getBatchResult();
    }

    @Override
    public void beforeStep(StepExecution stepExecution) {
    }

    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        batchResult.setTotalCount(Integer.valueOf(stepExecution.getReadCount()).longValue());
        batchResult.setSkippedCount(Integer.valueOf(stepExecution.getSkipCount()).longValue());
        batchResult.setFilterCount(Integer.valueOf(stepExecution.getFilterCount()).longValue());
        return super.afterStep(stepExecution);
    }
}
